#define multiimgupload(x)
     #if(IMAGE_HOST == "")
		<div class="form-group">
			<div class="col-sm-10" id="_#(x.index??)_BTN">
				<label class="control-label no-padding-right" id="_#(x.index??)_upload" style="cursor:pointer;"><i class="fa fa-cloud-upload"></i>&nbsp;选择图片</label>&nbsp;&nbsp;
				<input type="hidden" id="_#(x.index??)" data-type="multiimgupload" name="token_#(table??x.table).#(x.index??)" #(x.required??) value="" data-key="上传" data-target="_#(x.index??)_upload" class="form-control"/>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12" id="_#(x.index??)_multiimg_upload">
			</div>
		</div>
		<div class="form-group" style="display:none;">
			<textarea  id="_#(x.index??)_editor" name="#(x.index??)_editor" ></textarea>
		</div>
		<script charset="utf-8" src="/static/kindeditor/kindeditor-all-min.js"></script>
		<script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>
		<script type="text/javascript">
		function _#(x.index??)_loadmultiimgupload(){
			var editor = KindEditor.create('textarea[name="#(x.index??)_editor"]', {
				uploadJson : '/kindeditor/upload_#(x.blob??'json')',
				fileManagerJson : '/kindeditor/file_manager_json',
				allowFileManager : false,
				extraFileUploadParams : { uploadType : "#(x.uploadType)",typeCode:"#(x.typeCode)",attachId:"#(x.attachId)",table:"#(x.table)"},
				imageSizeLimit:'5MB'
			});
			
			KindEditor("#_#(x.index??)_upload").click(function () {
        		editor.loadPlugin('multiimage',function(){
        			editor.plugin.multiImageDialog({
						clickFn : function(urlList) {
							var imgArray = [];
							KindEditor.each(urlList, function(i, data) {
								imgArray.push(data.title);
								$("#_#(x.index??)_multiimg_upload").append("<img id='img_"+data.title+"'  layer-pid='img_"+data.title+"' layer-src='"+data.url+"' width=100 src='"+data.url+"' style='display:inline-block;margin-left:12px;padding:2px; border:1px solid #ccc;cursor:pointer;width:#(x.width??'170px');height:#(x.height??'110px');'></img><i class='fa fa-times img-delete' onclick=\"_#(x.index??)_deleteImg('"+data.title+"')\"></i>");
							});
							var _name = $("#_#(x.index??)").attr("name").replace("token_", "");
							$("#_#(x.index??)").attr("name", _name);
							var fileds = $("#_#(x.index??)").val();
							if(fileds!=""){
								$("#_#(x.index??)").val(fileds + "," + imgArray.join(","));
							}else{
								$("#_#(x.index??)").val(imgArray.join(","));
							}
							
							layer.photos({
								  photos: '#_#(x.index??)_multiimg_upload'
								  ,closeBtn:1
								  ,full: true
								  ,scrollbar: true
								  ,shade: [0.5, '#393D49']
								  ,shadeClose:true
								  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
							}); 
							
							$("#form_token").val(1);
							editor.hideDialog();
						}
					});
        		});
            });
		}
			
			function _#(x.index??)_initMultiImgUpload(ids, type){
				_#(x.index??)_loadmultiimgupload();
				if(type == "view"){
					$("#_#(x.index??)_BTN").css("display", "none");
					
				}
				var fileArry = ids.split(',');
				for(var i=0 ; i < fileArry.length;i++){
					var url = "/kindeditor/renderFile/"+fileArry[i];
					if(type =="view"){
						$("#_#(x.index??)_multiimg_upload").append("<img id='img_"+fileArry[i]+"' layer-pid='img_"+fileArry[i]+"' layer-src='"+url+"' width=100 src='"+url+"' style='display:inline-block;margin-left:12px;padding:2px; border:1px solid #ccc;cursor:pointer;width:#(x.width??'170px');height:#(x.height??'110px');'></img>");
					}else{
						$("#_#(x.index??)_multiimg_upload").append("<img id='img_"+fileArry[i]+"' layer-pid='img_"+fileArry[i]+"' layer-src='"+url+"' width=100 src='"+url+"' style='display:inline-block;margin-left:12px;padding:2px; border:1px solid #ccc;cursor:pointer;width:#(x.width??'170px');height:#(x.height??'110px');'></img><i id='i_"+fileArry[i]+"' class='fa fa-times img-delete' onclick=\"_#(x.index??)_deleteImg('"+fileArry[i]+"')\"></i>");
					}
					
				}
				
				layer.photos({
					  photos: '#_#(x.index??)_multiimg_upload'
					  ,closeBtn:1
					  ,full: true
					  ,scrollbar: true
					  ,shade: [0.5, '#393D49']
					  ,shadeClose:true
					  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
				}); 
			}
			
			function _#(x.index??)_deleteImg(fileId){
				 layer.confirm('确认删除文件吗？', {
		                icon: 3,
		                btn: ['确定', '取消'] //按钮
		            }, function (index) {
		            	layer.close(index);
		             	var appindex = appLoading();
		    			var ajax = new $ax("/kindeditor/deleteFile", function(data){
		    				if (data.state == 'ok') {
		    					clearLoading(appindex);
		    					var fileds = $("#_#(x.index??)").val();
		    					var fileArry = fileds.split(',');
		    					var index = fileArry.indexOf(fileId);
		    					if (index > -1) {
		    						fileArry.splice(index, 1);
		    					}
		    					$("#_#(x.index??)").val(fileArry.join(","));
		    					$("#img_"+fileId).remove();
		    					$("#i_"+fileId).remove();
		    					
		    					var _name = $("#_#(x.index??)").attr("name").replace("token_", "");
		    					$("#_#(x.index??)").attr("name", _name);
		    					$("#form_token").val(1);
		    					return false;
		    				} else {
		    					clearLoading(appindex);
		    					if(data.state == 'fail'){
		    						layer.alert(data.msg, {icon: 5,title:"发生错误"});
		    					}
		    					else{
		    						layer.msg(data.msg, {icon: 2,time:2000});
		    					}
		    					return false;
		    				}
		    			});
		    			ajax.set("fileId",fileId);
		    			ajax.start();	
		            }, function () {
		              
		        });
			}
		</script>
		<style>
	        .img-delete {
			    cursor: pointer;
			    position:absolute;
			}
		</style>
		 #end
#end
